<template>
  <div class="mui-numbox" data-numbox-step="1" data-numbox-min="1">
    <button class="mui-btn mui-numbox-btn-minus" type="button">-</button>
    <input class="mui-numbox-input" type="number" @change="iptChange" ref="ipt">
    <button class="mui-btn mui-numbox-btn-plus" type="button">+</button>
  </div>
</template>

<script>
import mui from "../../lib/mui/js/mui.min.js";

export default {
  mounted() {
    mui(".mui-numbox").numbox();
  },
  created() {
    console.log("created =" + this.max);
  },
  data() {
    return {
      count: 1,
      max: this.maxCount
    };
  },
  methods: {
    iptChange() {
      // console.log('改变了数量:' + this.$refs.ipt.value);
      // 当前获取到的是字符串，需要处理一下
      this.$emit("getCount", Number.parseInt(this.$refs.ipt.value));
    }
  },
  props: ["maxCount"],
  watch: {
    maxCount: function(newVal, oldVal) {
      console.log("newVal = " + newVal);
      mui(".mui-numbox")
        .numbox()
        .setOption("max", newVal);
    }
  }
};
</script>   


<style lang="scss" scoped>
</style>
